// myself/login/login.js
import api from '../../utils/api.js';
import network from '../../utils/network.js';
import notice from '../../utils/notice.js';
import wechat from '../../utils/wechat.js';
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    style: app.globalData.style,
    visible: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },
  onReady () {
    this.setData({ visible: true })
  },
  onClose (e) {
      console.log(e);
  },
  closePopup () {},
  getUserInfo(e) {
    console.log(e)
  },

  chooseAvatar(e) {
    console.log(e)
  },

  getPhoneNumber(e) {
    console.log('getPhoneNumber 回调:', e.detail)
    //   console.log(app);
    // network.getJson(api.getUserPhoneNumber, {
    //   userId: app.globalData.userInfo.id,
    //   code: e.detail.code
    // }).then(res => {
    //   console.log(res)
    //   app.globalData.userInfo.mobile = res;
    //   app.globalData.userInfo.name = '沙龙汇用户'
    //   return network.postJson(api.updateUser, app.globalData.userInfo)
    // }).then(res => {
    //   notice.postNotice("UserInfo");
    //   wx.showToast({
    //     title: '登录成功',
    //   })
    //   setTimeout(function () {
    //     wx.navigateBack();
    //   }, 2000)
    // })
  },

  loginTap() {
    wechat.saveUserInfo(network, api.updateUser, app.globalData.userInfo).then(res => {
      app.globalData.userInfo = res;
      notice.postNotice("UserInfo");
      wx.showToast({
        title: '登录成功',
      })
      setTimeout(function () {
        wx.navigateBack();
      }, 2000)
    })
  },
  navigateBack () {
    wx.navigateBack()
  },
})